﻿<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
	CodeBehind="Default.aspx.cs" Inherits="MyAnt.TestHost.Web._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
	<script type="text/javascript" src="Scripts/ThreeCanvas.js"></script>
	<script type="text/javascript" src="Scripts/ThreeExtras.js"></script>
	<script type="text/javascript" src="Scripts/Stats.js"></script>
	<script type="text/javascript" src="Scripts/dat.gui.min.js"></script>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
	<style type="text/css">
		html, body { width:100%; height:100%; margin:0px; padding:0px; }
		body { background-color: #000; color: #ddd; }
	</style>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<script type="text/javascript">
	var container, stats;
	var camera, scene, renderer;
	var cameraValues = {
		lookAt: { x: 200, y: 200, z: 200 },
		position: { x: -500, y: 500, z: -500, animated: false }
	};
	var subgeo = new THREE.Geometry();

	function init() {
		container = document.createElement('div');
		document.body.appendChild(container);

		var info = document.createElement('div');
		info.style.position = 'absolute';
		info.style.top = '0px';
		info.style.width = '100%';
		info.style.textAlign = 'center';
		info.innerHTML = '';
		container.appendChild(info);

		camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 10000);
		camera.position.x = cameraValues.position.x;
		camera.position.y = cameraValues.position.y;
		camera.position.z = cameraValues.position.z;

		scene = new THREE.Scene();

		scene.add(camera);

		initSector(subgeo);

		var ambientLight = new THREE.AmbientLight(120);
		scene.add(ambientLight);
			
		renderer = new THREE.CanvasRenderer();
		renderer.setSize(window.innerWidth, window.innerHeight);

		container.appendChild(renderer.domElement);

		stats = new Stats();
		stats.domElement.style.position = 'absolute';
		stats.domElement.style.top = '0px';
		container.appendChild(stats.domElement);
	}

	function animate() {
		requestAnimationFrame(animate);
		render();
		stats.update();
	}

	//var ticks = 0;
	function render() {
		var timer = new Date().getTime() * 0.0005;

		if (cameraValues.position.animated) {
			camera.position.x = Math.cos(timer) * cameraValues.position.x;
			camera.position.y = cameraValues.position.y;
			camera.position.z = Math.sin(timer) * cameraValues.position.z;
			/*if (ticks++ > 10) {
				var geometry = new THREE.CubeGeometry(5, 5, 5);
				var cube1 = new THREE.Mesh(geometry, new THREE.MeshBasicMaterial({ color: '0xff0000', opacity: 0.5, shading: THREE.FlatShading, overdraw: true }));
				cube1.position.x = 1 * camera.position.x;
				cube1.position.y = 1 * camera.position.y;
				cube1.position.z = 1 * camera.position.z;
				cube1.overdraw = true;
				scene.add(cube1);
				ticks = 0;
			}*/
		}
		else {
			camera.position.x = cameraValues.position.x;
			camera.position.y = cameraValues.position.y;
			camera.position.z = cameraValues.position.z;
		}
		camera.lookAt({ x: cameraValues.lookAt.x, y: cameraValues.lookAt.y, z: cameraValues.lookAt.z });

		renderer.render(scene, camera);
	}

	window.onload = function () {
		var gui = new dat.GUI();
		var guiCamPos = gui.addFolder('Camera position');
		guiCamPos.add(cameraValues.position, 'x').min(-1000).max(1000).step(.5);
		guiCamPos.add(cameraValues.position, 'y').min(-1000).max(1000).step(.5);
		guiCamPos.add(cameraValues.position, 'z').min(-1000).max(1000).step(.5);
		guiCamPos.add(cameraValues.position, 'animated');
		var guiCamLookAt = gui.addFolder('Look at point');
		guiCamLookAt.add(cameraValues.lookAt, 'x').min(-1000).max(1000).step(.5);
		guiCamLookAt.add(cameraValues.lookAt, 'y').min(-1000).max(1000).step(.5);
		guiCamLookAt.add(cameraValues.lookAt, 'z').min(-1000).max(1000).step(.5);
	}

	init();
	animate();
</script>
</asp:Content>
